function getUrl(name) {
    var res = "";
    $.ajax({  
        type:'get',      
        url:'js/config.json',
        async : false, 
        dataType: "json",  
        success:function(data){
            res = data.url[name];
            //console.log(res);
        }  
    });
    return res;
}
function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1),
            strs = str.split("&");
        for (var i = 0,len = strs.length; i < len; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}
function drawCircle(obj,max,val){
    var num = (val/max)*100 * 3.6;
    if (num<=180) {
        //obj.find('.circle_right').css('transform', "rotate(" + num + "deg)");
        obj.find('.circle_right').css('-webkit-transform', "rotate(" + num + "deg)");
    } else if(num>=360){
        obj.find('.circle_right').css('-webkit-transform', "rotate(180deg)");
        obj.find('.circle_left').css('-webkit-transform', "rotate(180deg)");
    } else{
        //obj.find('.circle_right').css('transform', "rotate(180deg)");
        obj.find('.circle_right').css('-webkit-transform', "rotate(180deg)");
        //obj.find('.circle_left').css('transform', "rotate(" + (num - 180) + "deg)");
        obj.find('.circle_left').css('-webkit-transform', "rotate(" + (num - 180) + "deg)");
    };
    obj.find('.cachenum').html(val);
}
function changeColor(obj,val){
    if (val == "True") {
        obj.css('background','#00cf41');
    }else if (val == "False") {
        obj.css('background','#f00');
    }else{
        obj.css('background','#666');
    }
}
function reset(){
    $('.u-box').find('p').html("");
    $('.u-box').removeClass('printed');
    $('.u-box').removeClass('break1');
    $('.u-box').removeClass('break');
    $('.u-box').removeClass('empty');
    $('.u-box').removeClass('backprinted');
    $('.u-box').removeClass('backprinted2');
    $('.u-box').removeClass('prewprinted');
    $('.u-box').removeClass('printed1');
    $('.u-box').removeClass('printed3');
}
function addanimate(obj){
    for (var i = 0,len = obj.length; i < len; i++) {
       (function(i){
            if (obj[i].isPause == 0){
                $('.u-box'+obj[i].stack_index).parent().addClass('moveleft');
            }

       })(i); 
    }
}
function count(obj,index){
    for (var i = 0,len = obj.length; i < len; i++) {
       (function(i){
            if (obj[i].silicon_id && obj[i].silicon_id != '0') {
                $('.u-box'+obj[i].stack_index).find('p').html(obj[i].silicon_id);
                if (obj[i].silicon_status == 1) {
                    if (index == 0) {
                        $('.u-box'+obj[i].stack_index).addClass('prewprinted');
                    }else if (index == 1) {
                        $('.u-box'+obj[i].stack_index).addClass('break1');
                    }else if(index == 2){
                        $('.u-box'+obj[i].stack_index).addClass('break1');
                    }else if(index == 3){
                        $('.u-box'+obj[i].stack_index).addClass('break');
                    }else if(index == 4){
                        $('.u-box'+obj[i].stack_index).addClass('break');
                    }else{
                        $('.u-box'+obj[i].stack_index).addClass('break');
                    }
                }else if(obj[i].silicon_status == 0){
                    if (index == 0) {
                        $('.u-box'+obj[i].stack_index).addClass('prewprinted');
                    }else if (index == 1) {
                        $('.u-box'+obj[i].stack_index).addClass('backprinted');
                    }else if(index == 2){
                        $('.u-box'+obj[i].stack_index).addClass('backprinted2');
                    }else if(index == 3){
                        $('.u-box'+obj[i].stack_index).addClass('printed1');
                    }else if(index == 4){
                        $('.u-box'+obj[i].stack_index).addClass('printed');
                    }else{
                        $('.u-box'+obj[i].stack_index).addClass('printed3');
                    }
                }else{
                    if (index == 0) {
                        $('.u-box'+obj[i].stack_index).addClass('prewprinted');
                    }else if (index == 1) {
                        $('.u-box'+obj[i].stack_index).addClass('backprinted');
                    }else if(index == 2){
                        $('.u-box'+obj[i].stack_index).addClass('backprinted2');
                    }else if(index == 3){
                        $('.u-box'+obj[i].stack_index).addClass('printed1');
                    }else if(index == 4){
                        $('.u-box'+obj[i].stack_index).addClass('printed');
                    }else{
                        $('.u-box'+obj[i].stack_index).addClass('printed3');
                    }
                }
            }
            
       })(i); 
    }
}
function cacheRender(){
    $('.u-cachelist').html("");
    var cachehtml = "";
    for (var i = 0,len = si.cache_list?si.cache_list.length:0; i < len; i++) {
       (function(i){
            cachehtml += '<div class="u-cacheinfo">'+si.cache_list[i].silicon_id+'</div>';
       })(i); 
    }
    $('.u-cachelist').append(cachehtml);
}
function errorRender(){
    $('.u-errorlistcon').html("");
    //si.err_list = ['2017-08-16 xxx异常'];
    var errorhtml = "";
    for (var i = 0,len = si.err_list?si.err_list.length:0; i < len; i++) {
       (function(i){
            errorhtml += '<p>'+si.err_list[i]+'</p>';
       })(i); 
    }
    $('.u-errorlistcon').append(errorhtml);
}
function DateDiff(d1,d2){
    var day = 24 * 60 * 60 * 1000;
    try {
        d1 = d1.substring(0,10);
        d2 = d2.substring(0,10);
        var dateArr = d1.split("-");
        var checkDate = new Date();
        checkDate.setFullYear(dateArr[0], dateArr[1] - 1, dateArr[2]);
        var checkTime = checkDate.getTime();

        var dateArr2 = d2.split("-");
        var checkDate2 = new Date();
        checkDate2.setFullYear(dateArr2[0], dateArr2[1] - 1, dateArr2[2]);
        var checkTime2 = checkDate2.getTime();

        var cha = (checkTime - checkTime2) / day;
        return cha;
    } catch (e) {
        return false;
    }
}
function AddDays(date,days){
    var hms = date.substring(10);
    var nd = new Date(date);
    nd = nd.valueOf();
    nd = nd + days * 24 * 60 * 60 * 1000;
    nd = new Date(nd);
    //alert(nd.getFullYear() + "年" + (nd.getMonth() + 1) + "月" + nd.getDate() + "日");
    var y = nd.getFullYear();
    var m = nd.getMonth() + 1;
    var d = nd.getDate();
    if (m <= 9) m = "0" + m;
    if (d <= 9) d = "0" + d;
    var cdate = y + "-" + m + "-" + d + " " +hms;
    return cdate;
}
function csvDownload(name,obj,data){
    //var str = "栏位1,栏位2,栏位3\n值1,值2,值3";
    var header = data.header;
    var body = data.body;
    var str = header.join(',') + '\n'
    for (var i = 0; i < body.length; i++) {
        var item = body[i];
        item.forEach(function(item, index, list) {
            str = str + item + ','
        })
        str = str + '\n'
    }
    obj.download = name+'.csv';
    //str = encodeURIComponent(str);
    //link.setAttribute("href", URL.createObjectURL(blob));
    var blob = new Blob(["\ufeff" + str], {type: 'text/csv,charset=ANSI'}); //解决数据过多下载失败
    obj.setAttribute("href", URL.createObjectURL(blob));
}
function getNowFormatDate(obj) {
    var seperator1 = "-",
        seperator2 = ":",
        month = obj.getMonth() + 1,
        strDate = obj.getDate(),
        hours = obj.getHours(),
        minutes = obj.getMinutes(),
        seconds = obj.getSeconds();

    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    if (hours >= 1 && hours <= 9) {
        hours = "0" + hours;
    }
    if (minutes >= 1 && minutes <= 9) {
        minutes = "0" + minutes;
    }
    if (seconds >= 1 && seconds <= 9) {
        seconds = "0" + seconds;
    }
    var currentdate = obj.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + hours + seperator2 + minutes + seperator2 + seconds;
    return currentdate;
}
Date.prototype.format = function(fmt) 
{ //author: meizz 
  var o = { 
    "M+" : this.getMonth()+1,                 //月份 
    "d+" : this.getDate(),                    //日 
    "h+" : this.getHours(),                   //小时 
    "m+" : this.getMinutes(),                 //分 
    "s+" : this.getSeconds(),                 //秒 
    "q+" : Math.floor((this.getMonth()+3)/3), //季度 
    "S"  : this.getMilliseconds()             //毫秒 
  }; 
  if(/(y+)/.test(fmt)) 
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); //格式化年份
  for(var k in o) //循环获取上面定义的月、日、小时等，格式化对应的数据。
    if(new RegExp("("+ k +")").test(fmt)) 
  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); 
  return fmt; 
}
function timeminus(date2,date1){
    var date1 = new Date(date1)
    var date2 = new Date(date2)
     
    var s1 = date1.getTime(),s2 = date2.getTime();
    var total = (s2 - s1)/1000;
    return total;
}
function timeplus(date1,time){
    var date1 = new Date(date1)
     
    var s1 = date1.getTime();
    var t = new Date();
    t.setTime(s1 + (time*1000));
    return t.format("yyyy-MM-dd hh:mm:ss");
}
function getRandomColor(){    

  return (function(m,s,c){    
    return (c ? arguments.callee(m,s,c-1) : '#') +    
      s[m.floor(m.random() * 16)]    
  })(Math,'0123456789abcdef',5)    
}

function dateFormat(time, format){
    var t = new Date(time);
    var tf = function(i){return (i < 10 ? '0' : '') + i};
    return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){
        switch(a){
            case 'yyyy':
                return tf(t.getFullYear());
                break;
            case 'MM':
                return tf(t.getMonth() + 1);
                break;
            case 'mm':
                return tf(t.getMinutes());
                break;
            case 'dd':
                return tf(t.getDate());
                break;
            case 'HH':
                return tf(t.getHours());
                break;
            case 'ss':
                return tf(t.getSeconds());
                break;
        }
    })
};